package com.scagoods.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * @author yan
 * @date 2025/8/21
 */
@RestController
@RequestMapping(value = "/api/goods",produces = MediaType.APPLICATION_JSON_VALUE)
public class GoodApi {
    //调用微服务
    //private final RestTemplate restTemplate = new RestTemplate();//可以调用rest请求的方法
    private RestClient.Builder restClientBuilder;
    @Autowired
    public void setRestClientBuilder(RestClient.Builder restClientBuilder) {
        this.restClientBuilder = restClientBuilder;
    }

    //去除警告
    @SuppressWarnings("all")
    @GetMapping
    public ResponseEntity<Map> getGoods(){
        String url = "http://brand-api/api/human/id/{id}";
        //ResponseEntity<Map> responseEntity = restTemplate.getForEntity(url, Map.class,30);//路径 参数响应类型

        Map<String, Object> map = restClientBuilder.build().get().uri(url,30).retrieve().body(Map.class);
        return ResponseEntity.ok(map);
    }
}
